package com.zp.self.module.level_5_设计模式.结构型模式.Ⅵ_组合模式;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ：by Zeng Peng
 * @date ：Created 2022/6/30 22:27
 * @description ：
 */
public class Menu extends MenuComponent{
    List<MenuComponent> menuComponents  =new ArrayList<>();
    public Menu(String name, int level) {
        super(name, level);
    }

    @Override
    public void print() {
        for (int i = 0; i < level; i++)
            System.out.print("-");
        System.out.print(name);
        System.out.println();
        for (MenuComponent o :this.menuComponents )
            o.print();
    }

    @Override
    public void add(MenuComponent menuComponent) {
        menuComponents.add(menuComponent);
    }

    @Override
    public void remove(MenuComponent menuComponent) {
        menuComponents.remove(menuComponent);
    }

    @Override
    public MenuComponent getChild(int index) {
        return menuComponents.get(index);
    }

}
